﻿using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using System;
using System.Collections.Generic;
using System.Text;

namespace AppMain
{
    public enum Role_Status
    {
        None,
        LoadingMap,
    }

    public class NetRole : ActionRole
    {
        public NetRole(IAttrMap attrMap) : base(attrMap)
        {
        }

        protected IChannelHandlerContext ctx;
        public Role_Status RoleStatus = Role_Status.None;
        public void setContext(IChannelHandlerContext ctx)
        {
            this.ctx = ctx;
        }

        public void send(short cmd, object message)
        {
            short HEAD_FIX = 0x71ab;
            short HEAD_LENG = 18;
            byte[] data = pb.ProtobufSerializer.Serialize(message);
            int len = data.Length;
            IByteBuffer buffer = Unpooled.Buffer();
            buffer.WriteShort(HEAD_FIX);
            buffer.WriteShort((short)(HEAD_LENG + len));
            buffer.WriteShort(cmd);
            buffer.WriteLong(UID);
            buffer.WriteInt(0);
            buffer.WriteBytes(data);
            ctx.WriteAndFlushAsync(buffer);
        }

    }

}
